<?php
class Dto {
    protected $_name;
    
    public function __construct($tablename = "", DataProvider $dbObj, $data=array()) {
        $this->_name = $tablename;
        $result = $dbObj->ExecuteQuery("SELECT * FROM {$tablename} LIMIT 0,1");
        while($field = mysql_fetch_field($result)) {
            $this->{$field->name} = NULL;
        }
        if(!empty($data)) {
            foreach($data as $key=>$value) {
                if(property_exists($this,$key)) {
                    $this->{$key} = $value;
                }
            }
        }
        $this->_init();   
    }
    
    protected function _init() {
        
    }
    
    public function toArray() {
        $arr = array();
        foreach($this as $key=>$value) {
            if(!empty($value)){
                $ref = new ReflectionProperty($this, $key);
                if($ref->isPublic()) {
                    $arr[$key] = $value;
                }
            }
        }
        return $arr;
    }
    public function __destruct(){
        
    }
}
?>